<template>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>公司名称</label>
                    <div class="layui-input-inline">
                        <input type="text" required="" class="layui-input" v-model="client">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>联系人姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" required="" class="layui-input" v-model="name">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>手机</label>
                    <div class="layui-input-inline">
                        <input type="text" required="" class="layui-input" v-model="phone">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>地址</label>
                    <div class="layui-input-inline">
                        <input type="text" required="" class="layui-input" v-model="district">
                    </div>
                </div>
                <div style="text-align: center">
                    <button class="layui-btn" @click="submitForm()">提交</button>
                </div>
            </form>
        </div>
    </div>
</template>

<script>
    import { mapActions, mapState } from "vuex";
    import service from "../../../src/service";
    export default {
        data(){
            return{
                id:"",
                client:"",
                name:"",
                phone:"",
                district:""
            }
        },
        methods:{
            submitForm(){
                var client = {
                    "name":this.name,
                    "phone":this.phone,
                    "client":this.client,
                    "district":this.district
                }
                service.instance().put("http://"+window.location.hostname+":8011/Client/add",client)
                    .then((response)=> {
                        if(response.data == "1"){
                            this.getClients();
                            this.$layer.alert("添加成功");
                            parent.closeAll()
                        }
                        else{
                            layer.msg(response.data, {icon: 2});
                        }
                    })
            },
            ...mapActions(["getClients"])
        },
        computed:{

        },
        mounted() {

        }
    }
</script>

<style scoped>

</style>